<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of Form
 *
 * @author Dennis
 */
class Tc_Helper_Form extends Zend_Controller_Action_Helper_Abstract {

    public $pluginLoader;

    public function __construct() {
        $this->pluginLoader = new Zend_Loader_PluginLoader();
    }

    public function direct($name, $options = null) {
        return $this->loadForm($name, $options);
    }

    public function loadForm($name, $options = null) {
        $module  = $this->getRequest()->getModuleName();
        $front   = $this->getFrontController();
        $default = $front->getDispatcher()->getDefaultModule();
        if (empty($module)) {
            $module = $default;
        }
        $moduleDirectory = $front->getControllerDirectory($module);
        $formsDirectory  = dirname($moduleDirectory) . '/forms';

        $prefix = (('default' == $module) ? '' : ucfirst($module) . '_')
                . 'Form_';
        $this->pluginLoader->addPrefixPath($prefix, $formsDirectory);

        $name      = ucfirst((string) $name);
        $formClass = $this->pluginLoader->load($name);
        return new $formClass($options);
    }
}
?>
